package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.KnowRelatedBean;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by wangqi on 2018/4/17.
 */

public class KnowRealtedAdapter extends BaseRecyclerViewAdapter<KnowRelatedBean.RowsBean> {

    public KnowRealtedAdapter(Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(inflater.inflate(R.layout.item_me_upcoming_work, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rHolder, final int position) {
        MyViewHolder holder = (MyViewHolder) rHolder;
        KnowRelatedBean.RowsBean bean = getItem(position);
        if (bean != null) {
            holder.tvTitleContent.setText(bean.getTitle());
            holder.tvDepartment.setText(bean.getCompanyName());
            if (!TextUtils.isEmpty(bean.getSendUserName())) {
                holder.tvName.setText("/" + bean.getSendUserName());
            }
            holder.tvOverdue.setVisibility(View.GONE);
            holder.tvTime.setText(bean.getCreateTime().replace("T", " "));

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnItemClickLitener != null) {
                        mOnItemClickLitener.onItemClick(view, position);
                    }
                }
            });
            //工单为0，问题为1
            if ("0".equals(bean.getType())) {
                if ("0".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("未指派");
                } else if ("3".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_76c56d);
                    holder.button.setText("已指派");
                } else if ("4".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e9981f);
                    holder.button.setText("处理中");
                } else if ("5".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_999691);
                    holder.button.setText("已关闭");
                } else if ("7".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("挂起");
                } else if ("9".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("待确认");
                } else if ("10".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_76c56d);
                    holder.button.setText("已解决");
                } else if ("11".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_999691);
                    holder.button.setText("已取消");
                } else if ("16".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("出发中");
                } else if ("17".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_76c56d);
                    holder.button.setText("已到达");
                } else if ("18".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("未指派");
                }
            } else if ("1".equals(bean.getType())) {
                if ("4".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("待申领");
                } else if ("1".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e9981f);
                    holder.button.setText("处理中");
                } else if ("2".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("待确认");
                } else if ("3".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("未解决");
                } else if ("6".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("已解决");
                } else if ("-6".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                    holder.button.setText("审核未通过");
                } else if ("7".equals(bean.getState())) {
                    holder.button.setBackgroundResource(R.drawable.shape_card_999691);
                    holder.button.setText("已关闭");
                }
            }
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tv_overdue)
        TextView tvOverdue;
        @Bind(R.id.tv_title_content)
        TextView tvTitleContent;
        @Bind(R.id.button)
        TextView button;
        @Bind(R.id.tv_department)
        TextView tvDepartment;
        @Bind(R.id.tv_name)
        TextView tvName;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
